package io.xccit.listener;

import io.xccit.service.IShopCartService;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author CH_ywx
 * @date 2023-09-21
 * @description 购物车MQ消息监听器
 */
@Component
public class ShopCartMQListener {

    @Autowired
    private IShopCartService shopCartService;

    /**
     * 监听消息队列发动的购物车消息,进行购物车列表清除操作
     * @param cartIds
     */
    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(name = "clear.queue"),
                    exchange = @Exchange(value = "topic.ex"),
                    key = {"clear.cart"}
            )
    )
    public void clear(List<Integer> cartIds){
        shopCartService.deleteByIds(cartIds);
    }
}
